local template = require "service.TemplateEngine.lib.resty.template"
local GetSchema = {}

json = gJson

local template_get = [[
{
	"msg": "{* param.msg *}",
	"code": {* param.code *},
	"group_cfg": {* tostring(json.encode(param.group_cfg)) *},
	"globalLockUser": "{* param.globalLockUser *}",
	"map_editor_cfg": {* tostring(json.encode(param.map_editor_cfg)) *},
	"category_cfg": [
		{% for k,vline in ipairs(param.category_cfg) do %}		{* tostring(json.encode(vline)) *}{* NeedFlags(not(k==#param.category_cfg), ",") *}
		{% end %}	],
	"levels": [
		{% for k,vline in ipairs(param.levels) do %}		{* tostring(json.encode(vline)) *}{* NeedFlags(not(k==#param.levels), ",") *}
		{% end %}	]
}]]

function GetSchema.Render(cfg, json)
	function NeedFlags(bFlag, flag)
		if bFlag then return flag end
		return ""
	end

	-- Using template.render
	return template.process(template_get, { param = cfg})
end

return GetSchema
